.netCHARTING v4.4 Documentation Send comments on this topic.
Label Alignment and Control
Getting Started > General Tutorials > Using labels > Label Alignment and Control

Glossary Item Box

Introduction

Each element contains a SmartLabel object with properties that affect the label's behavior. To show the element labels the following code can be used. The setting will propagate to all elements within the chart.

[C#]

Chart.DefaultElement.ShowValue = true;

[Visual Basic]

Chart.DefaultElement.ShowValue = True

Dynamic Labels

Force Label Drawing
Labels that cannot fit on the chart will not be shown by default. To force them to appear, the DynamicDisplay property must be set to false.

[C#]

Chart.DefaultElement.SmartLabel.DynamicDisplay = false;

[Visual Basic]

Chart.DefaultElement.SmartLabel.DynamicDisplay = False


Prevent Label Overlap
Non-column series type elements have labels which will dynamically move out of each others way to prevent overlap. When this happens,a line is drawn to indicate which element the label pertains to. This behavior can be turned off and on using the DynamicPosition property. The following code disables this feature:

[C#]

Chart.DefaultElement.SmartLabel.DynamicPosition = false;

[Visual Basic]

Chart.DefaultElement.SmartLabel.DynamicPosition = False

The line drawn to indicate the element can be modified through the SmartLabel.Line property.

Line caps can be used to make the indicator lines look like arrow pointers.

 

Label Alignment

Element labels also have several other alignment options available provided by the LabelAlignment enumeration.

Alignment
A label's default alignment is controled with the SmartLabel.Alignment property.

[C#]

Chart.DefaultElement.SmartLabel.Alignment = LabelAlignment.Top;

[Visual Basic]

Chart.DefaultElement.SmartLabel.Alignment = LabelAlignment.Top

Column Labeling

Secondary Alignment
Since there may not always be enough room to place the label in desired position (Alignment). The chart engine will look at the AlignmentSecondary property which is a collection of LabelAlignment objects and find the next best one that fits. The following code clears the default secondary alignment settings and sets two options labels can use.

[C#]

Chart.DefaultElement.SmartLabel.SecondaryAlignment.Clear();
Chart.DefaultElement.SmartLabel.SecondaryAlignment.Add(LabelAlignment.OutsideTop);
Chart.DefaultElement.SmartLabel.SecondaryAlignment.Add(LabelAlignment.Bottom);

[Visual Basic]

Chart.DefaultElement.SmartLabel.SecondaryAlignment.Clear()
Chart.DefaultElement.SmartLabel.SecondaryAlignment.Add(LabelAlignment.OutsideTop)
Chart.DefaultElement.SmartLabel.SecondaryAlignment.Add(LabelAlignment.Bottom)

Vertical Label
When a label doesn't fit into a column horizontally it will try to fit vertically. If the label is too tall to fit, the label font will decrease in size until it fits. For cases where columns have both horizontal and vertical labels, column labels may be difficult to read. If this is the case, all labels can be forced to show vertically by using this code:

[C#]

Chart.DefaultElement.SmartLabel.ForceVertical = true;

[Visual Basic]

Chart.DefaultElement.SmartLabel.ForceVertical = True

Note: This feature doesn't affect horizontal charts.